package p_103

import java.net.URL


/**
 * URL 的组成
 */
class TestProtocol {
    val urls = arrayOf("http://www.baidu.com", // 简单 超文本
            "https://www.baidu.com", // 安全http
            "ftp://ibibllio.org/pub/languages/java/javafaq/", // ftp 协议
            "mailto:15903648970@163.com", // 简单 邮件协议
            "telnet://dibner.poly.edu/",//telnet 协议
            "file://C:/Users/windows/Pictures",// 本地文件协议
            "ldap://ldap.itd.umich.edu/",
            "jdbc:mysql://luna.ibiblio.org:3306/test",// jdbc 协议
            "rmi://ibiblio.org/RenderEngine" // 远程方法定制协议
    )


    private fun testProtocol(url: String) {
        try {
            val u = URL(url)
            println("${u.protocol} is  supported")
        } catch (e: Exception) {
            val protocol = url.substring(0, url.indexOf(":"))
            println("$protocol is not supported")
        }
    }

    fun doSome() {
        for (url in urls) testProtocol(url)
    }

}